<!--页面组件-->
<template>
  <div>
    <div class="tempxyz tableHeight">
      <CCard class>
        <CCardHeader>
          <strong class="headerFont">执行中任务列表</strong>
        </CCardHeader>
        <CCardBody class="card-body">
          <div class="oneMargin" @keyup.enter="getTaskTableData()">
            <CRow class="twoMargin" style="margin-bottom: 10px">
              <CCol sm="4" class="myCol" style>
                <label class="labelName">任务名称</label>
                <Input
                  :title="groupName"
                  maxlength="50"
                  v-model="groupName"
                  placeholder="请输入任务名称搜索..."
                  style="width: 191px"
                />
                <!-- <span v-if="changestatus" class="hiddenbit" @click="clearmess">x</span> -->
              </CCol>
              <CCol sm="6" class="myCol">
                <label class="labelName youxianji" style>优先级</label>
                <RadioGroup v-model="priority" class="priorityMargin">
                  <Radio label>全部</Radio>
                  <Radio label="0">普通</Radio>
                  <Radio label="1">优先</Radio>
                </RadioGroup>
              </CCol>
            </CRow>
            <CRow class="rowMargin">
              <CCol sm="4" class="myCol">
                <label class="labelName">开始日期</label>
                <DatePicker
                  type="date"
                  placeholder="请选择开始日期"
                  v-model="startDate"
                  class="dateMargin"
                  style="width: 191px"
                  @on-change="onStartTimeChange"
                  :options="startTimeOption"
                  :editable="false"
                ></DatePicker>
              </CCol>
              <CCol sm="4" class="myCol endMargin">
                <label class="labelName">结束日期</label>
                <DatePicker
                  type="date"
                  placeholder="请选择结束日期"
                  v-model="endDate"
                  class="dateMargin"
                  @on-change="onEndTimeChange"
                  :options="endTimeOption"
                  :editable="false"
                ></DatePicker>
              </CCol>
              <CCol sm="3" class="myCol searchPosition">
                <CButton
                  v-c-tooltip="'搜索'"
                  color="info"
                  class="system-btn-style"
                  @click="getTaskTableData()"
                >
                  <CIcon name="cil-magnifying-glass" />&nbsp;搜索
                </CButton>
                <CButton
                  color="info"
                  @click="clearmess"
                  class="myCol clean system-btn-style"
                >
                  <img
                    src="@/assets/icons/chongzhi.png"
                    style="width: 15px; height: 15px"
                    alt
                  />&nbsp; 重置
                </CButton>
              </CCol>
            </CRow>
          </div>
          <div style="height: calc(100% - 158px)">
            <TableList ref="table" :getColumn="getColumns" :getAxios="getAxios">

              <template v-slot:show_details1="item">
                <div v-if="item.data.row.status == 8||item.data.row.status == 1">
                  <CSelect
                          :disabled="$store.getters.getBtnProcessPriority && $store.getters.getBtnProcessPriority.enableFlag == '1'"
                          horizontal
                          :options="priorityShowList"
                          :value.sync="item.data.row.priority"
                          class="prioritySelect onButton selectStyle"
                          @change="selectPriorityChange($event, item.data.row)"
                  ></CSelect>
                </div>
                <div v-else>{{ item.data.row.priority == 0 ? "普通" : "优先" }}</div>
                <!--   <span v-if="item.data.row.priority == 1"> 优先 </span>
                   <span v-if="item.data.row.priority == 0"> 普通 </span>-->
              </template>
              <template v-slot:show_details2="item">
                <div class="buttonStatus">
                  <CButton
                    v-if="
                      item.data.row.status == 1 && item.data.row.isHuman == 1
                    "
                    class="stastusBtn executing onButton"
                    >执行中</CButton
                  >
                  <CButton
                    v-if="
                      item.data.row.status == 1 && item.data.row.isHuman == 0
                    "
                    class="stastusBtn executing onButton"
                    >执行中</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 2"
                    class="stastusBtn pause onButton"
                    >暂停</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 3"
                    style="color: #f9b115"
                    class="onButton"
                    >删除</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 4"
                    class="stastusBtn success onButton"
                    >完成</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 5"
                    class="stastusBtn success onButton"
                    >完成</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 6"
                    style="color: #f9b115"
                    class="onButton"
                    >超时</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 7"
                    class="stastusBtn stop onButton"
                    >停止</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 8"
                    class="stastusBtn pending onButton"
                    >待执行</CButton
                  >
                </div>
              </template>
              <template v-slot:show_imageNumber="item">
                <span>
                  {{ item.data.row.imageNumber }} ({{
                    item.data.row.successNumber
                  }}/{{ item.data.row.failNumber }})
                </span>
              </template>
              <template v-slot:show_details="item">

                <Poptip  trigger="hover" word-wrap width="215">

                  <CButton
                      title="查看子任务"
                      variant="outline"
                      class="textBtnStyle onButton system-btn-style"
                      @click="getInfo(item.data.row)"
                  >
                    查看
                  </CButton>
                  <CButton
                      title="删除"
                      variant="outline"
                      @click="del(item.data.row)"
                      class="textBtnStyle onButton system-btn-style"
                      data-permission="Btn_ToExecute_Del"
                  >
                    删除
                  </CButton>
                  <div class="api" slot="content">
                    <CButton
                        :disabled="item.data.row.taskType == 2 ? false : true"
                        v-if="item.data.row.taskType == 2"
                        title="详情"
                        variant="outline"
                        class="textBtnStyle onButton system-btn-style"
                        @click="getTaskDetails(item.data.row)"
                    >
                      详情
                    </CButton>
                    <CButton
                        :disabled="true"
                        v-if="item.data.row.taskType != 2"
                        title="详情"
                        variant="outline"
                        class="disableTextBtnStyle onButton system-btn-style"
                        @click="() => {}"
                    >
                      详情
                    </CButton>
                    <!-- <CButton
                       :disabled="item.data.row.status == 1 ? false : true"
                       v-if="item.data.row.status == 1"
                       title="暂停"
                       variant="outline"
                       class="textBtnStyle onButton system-btn-style"
                       @click="pause(item.data.row)"
                       data-permission="Btn_ToExecute_Pause"
                     >
                       暂停
                     </CButton>
                     <CButton
                       :disabled="item.data.row.status == 2 ? false : true"
                       title="恢复"
                       v-if="item.data.row.status == 2"
                       variant="outline"
                       class="textBtnStyle onButton system-btn-style"
                       @click="restore(item.data.row)"
                       data-permission="Btn_ToExecute_Retore"
                     >
                       恢复
                     </CButton>
                     <CButton
                       :disabled="true"
                       v-if="item.data.row.status != 1 && item.data.row.status != 2"
                       title="暂停"
                       variant="outline"
                       class="disableTextBtnStyle onButton"
                       @click="() => {}"
                       data-permission="Btn_ToExecute_Pause"
                     >
                       暂停
                     </CButton>-->
                    <CButton
                        :disabled="item.data.row.status == 1 ? false : true"
                        v-c-tooltip="'终止'"
                        title="终止"
                        v-if="item.data.row.status == 1"
                        variant="outline"
                        class="textBtnStyle onButton system-btn-style"
                        @click="stop(item.data.row)"
                        data-permission="Btn_ToExecute_Restar"
                    >
                      终止
                    </CButton>
                    <CButton
                        :disabled="item.data.row.status == 7 ? false : true"
                        title="重启"
                        v-if="item.data.row.status == 7"
                        variant="outline"
                        class="textBtnStyle onButton system-btn-style"
                        @click="reStart(item.data.row)"
                        data-permission="Btn_ToExecute_Restar"
                    >
                      重启
                    </CButton>
                    <CButton
                        :disabled="true"
                        title="终止"
                        v-if="item.data.row.status != 1 && item.data.row.status != 7"
                        variant="outline"
                        class="disableTextBtnStyle onButton"
                        @click="() => {}"
                        data-permission="Btn_ToExecute_Restar"
                    >
                      终止
                    </CButton>
                  </div>
                </Poptip>
              </template>
            </TableList>
          </div>
        </CCardBody>
        <!--CDataTable表格-->
        <!--          <CDataTable
            class="tablePosition"
            :items="data"
            :fields="fields"
            hover
            border
          >
            <template #show_details1="{ item }">
              <td>
                <span v-if="item.priority == 1">
                  优先
                  &lt;!&ndash; <span>P1</span> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/highPriority.svg" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/p1.png" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../../public/img/P1.svg" class="levelstyle" alt /> &ndash;&gt;
                </span>
                <span v-if="item.priority == 0">
                  普通
                  &lt;!&ndash; <span>P2</span> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/middlePriority.svg" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/p2.png" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../../public/img/P2.svg" class="levelstyle" alt /> &ndash;&gt;
                </span>
              </td>
            </template>
            <template #show_userName="{ item }">
              <td>
                <span v-html="getUserName(item)"></span>
              </td>
            </template>
            <template #show_imageNumber="{ item }">
              <td>
                <span>
                  {{ item.imageNumber }} ({{ item.successNumber }}/{{
                    item.failNumber
                  }})
                </span>
              </td>
            </template>
            <template #show_details2="{ item }">
              <td>
                <button v-if="item.status == 1" class="stastusBtn executing">
                  执行中
                </button>
                <button v-if="item.status == 2" class="stastusBtn pause">
                  暂停
                </button>
                <button v-if="item.status == 3" style="color: #f9b115">
                  删除
                </button>
                <button v-if="item.status == 4" class="stastusBtn success">
                  完成
                </button>
                <button v-if="item.status == 5" class="stastusBtn success">
                  完成
                </button>
                <button v-if="item.status == 6" style="color: #f9b115">
                  超时
                </button>
                <button v-if="item.status == 7" class="stastusBtn stop">
                  停止
                </button>
                <button v-if="item.status == 8" class="stastusBtn pending">
                  待执行
                </button>
              </td>
            </template>
            <template #show_details="{ item }">
              <td>
                <CButton
                  title="查看子任务"
                  variant="outline"
                  class="textBtnStyle"
                  @click="getInfo(item)"
                >
                  查看
                </CButton>
                <CButton
                  :disabled="item.taskType == 2 ? false : true"
                  title="详情"
                  variant="outline"
                  class="textBtnStyle"
                  @click="getTaskDetails(item)"
                >
                  详情
                </CButton>

                <CButton
                  :disabled="item.status == 1 ? false : true"
                  v-if="item.status == 1"
                  title="暂停"
                  variant="outline"
                  class="textBtnStyle"
                  @click="pause(item)"
                  data-permission="Btn_InExecute_Pause"
                >
                  暂停
                </CButton>
                <CButton
                  :disabled="item.status == 2 ? false : true"
                  title="恢复"
                  v-if="item.status == 2"
                  variant="outline"
                  class="textBtnStyle"
                  @click="restore(item)"
                  data-permission="Btn_InExecute_Restore"
                >
                  恢复
                </CButton>
                <CButton
                  :disabled="true"
                  v-if="item.status != 1 && item.status != 2"
                  title="暂停"
                  variant="outline"
                  class="disableTextBtnStyle"
                  @click="() => {}"
                  data-permission="Btn_InExecute_Pause"
                >
                  暂停
                </CButton>
                <CButton
                  :disabled="item.status == 1 ? false : true"
                  title="终止"
                  v-if="item.status == 1"
                  variant="outline"
                  class="textBtnStyle"
                  @click="stop(item)"
                  data-permission="Btn_InExecute_Restar"
                >
                  终止
                </CButton>
                <CButton
                  :disabled="item.status == 7 ? false : true"
                  title="重启"
                  v-if="item.status == 7"
                  variant="outline"
                  class="textBtnStyle"
                  @click="reStart(item)"
                  data-permission="Btn_InExecute_Restar"
                >
                  重启
                </CButton>
                <CButton
                  :disabled="true"
                  title="终止"
                  v-if="item.status != 1 && item.status != 7"
                  variant="outline"
                  class="disableTextBtnStyle"
                  @click="() => {}"
                  data-permission="Btn_InExecute_Restar"
                >
                  终止
                </CButton>

                <CButton
                  title="删除"
                  variant="outline"
                  @click="del(item)"
                  class="textBtnStyle"
                  data-permission="Btn_InExecute_Del"
                >
                  删除
                </CButton>
              </td>
            </template>
          </CDataTable>
        </CCardBody>
        <CCardFooter class="page-link">
          <CRow>
            <CCol class="footerPage" style>
              <span class="pageContent">
                每页
                <CSelect
                  @change="getVendorId($event)"
                  :options="[10, 15, 20, 25]"
                  v-model="pageSize"
                  class="selectStyle"
                  style
                />
                条记录。第{{ this.currentPage }}页(总共{{ this.total }}页，{{
                  this.allNum
                }}条记录)
              </span>
              <CPagination
                :activePage.sync="currentPage"
                :pages="total"
                align="end"
                v-if="total != 0"
              />
            </CCol>
          </CRow>
        </CCardFooter>-->
      </CCard>
    </div>

    <!-- <CModal
      :show.sync="delShow"
      :closeOnBackdrop="false"
      title="删除主任务"
      centered
    >
      <template #header>
        <img src="@/assets/icons/shanchu.svg" alt />
        <p class="delKuangShow">删除主任务</p>
      </template>
      <div class="modalBody">
        <p>删除主任务时与主任务相关的信息都会丢失</p>
        <p>请确认是否删除?</p>
      </div>
      <template #footer class="footerBtns">
        <CButton @click="delCancel" color="info" class="cancel-btn">取消</CButton>
        <CButton @click="delOk" color="info">确定</CButton>
      </template>
    </CModal>
    <CModal
      :show.sync="pauseShow"
      :closeOnBackdrop="false"
      title="暂停任务"
      centered
    >
      <p>确认要暂停任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="pauseCancel" color="info">取消</CButton>
        <CButton @click="pauseOk" color="info">确定</CButton>
      </template>
    </CModal>
    <CModal
      :show.sync="restoreShow"
      :closeOnBackdrop="false"
      title="恢复任务"
      centered
    >
      <p>确认要恢复任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="restoreCancel" color="info">取消</CButton>
        <CButton @click="restoreOk" color="info">确定</CButton>
      </template>
    </CModal>
    <CModal
      :show.sync="restartShow"
      :closeOnBackdrop="false"
      title="重启任务"
      centered
    >
      <p>确认要重启任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="reStartCancel" color="info">取消</CButton>
        <CButton @click="reStartOk" color="info">确定</CButton>
      </template>
    </CModal> -->

    <Modal
      v-model="delShow"
      draggable
      scrollable
      title="删除主任务"
      :styles="modalStyle"
    >
      <p slot="header" class="modalHeader">
        <img src="@/assets/icons/shanchu.svg" alt />
        <span style="margin-left: 5px">删除主任务</span>
      </p>
      <div class="modalBody">
        <p>删除主任务时与主任务相关的信息都会丢失</p>
        <p>请确认是否删除?</p>
      </div>
      <template #footer class="footerBtns">
        <CButton @click="delCancel" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="delOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="pauseShow"
      draggable
      scrollable
      title="暂停任务"
      :styles="modalStyle"
    >
      <p>确认要暂停任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="pauseCancel" color="info" class="cancel-btn">取消</CButton>
        <CButton @click="pauseOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="restoreShow"
      draggable
      scrollable
      title="恢复任务"
      :styles="modalStyle"
    >
      <p>确认要恢复任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="restoreCancel" color="info" class="cancel-btn">取消</CButton>
        <CButton @click="restoreOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="restartShow"
      draggable
      scrollable
      title="重启任务"
      :styles="modalStyle"
    >
      <p>确认要重启任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="reStartCancel" color="info" class="cancel-btn">取消</CButton>
        <CButton @click="reStartOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="retryShow"
      draggable
      scrollable
      title="重试任务"
      :styles="modalStyle"
    >
      <p>确认要重试任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="retryCancel" color="info" class="cancel-btn">取消</CButton>
        <CButton @click="retryOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>


    <Modal
      v-model="stopShow"
      draggable
      scrollable
      title="终止任务"
      :styles="modalStyle"
    >
      <p>确认要终止任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="stopCancel" color="info" class="cancel-btn">取消</CButton>
        <CButton @click="stopOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <!-- 质检报告 -->
    <div>
      <QualityReport
        ref="refQcReportModal"
        v-show="qcReportModal"
        :modalShow="qcReportModal"
        @closed="qcReportModalClosed"
      ></QualityReport>
    </div>
  </div>
</template>

<!--js代码-->
<script>
import QualityReport from "../qualityCheck/qualityReport";
import TableList from "@/template/table/TableList";
const fields = [
  {
    label: "序号",
    key: "number",
    _style: "width:60px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "任务名称",
    key: "groupTaskName",
    _style: "width:auto;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "任务来源",
    key: "taskSourceName",
    _style: "width:auto;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "用户名",
    key: "show_userName",
    _style: "width:auto;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "开始时间",
    key: "createTime",
    _style: "width:170px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "结束时间",
    key: "endTime",
    _style: "width:170px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "优先级",
    key: "show_details1",
    _style: "width:75px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "景数(成功/失败)",
    key: "show_imageNumber",
    _style: "width:120px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "状态",
    key: "show_details2",
    _style: "width:90px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "操作",
    key: "show_details",
    _style: "width:300px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
];
export default {
  name: "taskExecute",
  components: {
    QualityReport,
    TableList,
  },
  data() {
    return {
      priorityShowList: [
        {
          label: "优先",
          value: 1,
        },
        {
          label: "普通",
          value: 0,
        },
      ],
      userName: window.sessionStorage.getItem("user"),
      modalStyle: { top: "340px" },
      qcReportModal: false,
      fields,
      restartShow: false,
      pauseShow: false,
      restoreShow: false,
      retryShow: false,
      stopShow: false,
      changestatus: false,
      delShow: false,
      clickId: "",
      loading: true,
      currentPage: 1,
      pages: 0,
      total: 0,
      allNum: 0,
      pageSize: 15,
      priority: "",
      taskStatus: "1",
      searchName: "",
      groupName: "",
      data: [],
      startDate: "",
      endDate: "",
      startTimeOption: {},
      endTimeOption: {},
      children: [],
      condtionList: {
        pageNum: "",
        pageSize: "",
        status: "",
        priorityLevel: "",
        startTime: "",
        endTime: "",
      },
      getColumns: [
        {
          title: "任务名称",
          key: "groupTaskName",
        },
        {
          title: "任务来源",
          key: "taskSourceName",
          width: 100,
          className: "centerText",
        },
        {
          title: "用户名",
          key: "taskOwner",
          width: 100,
          className: "centerText",
        },
        {
          title: "开始时间",
          key: "createTime",
          width: 170,
          className: "centerText",
        },
        {
          title: "结束时间",
          key: "endTime",
          width: 170,
          className: "centerText",
        },
        {
          title: "优先级",
          key: "show_details1",
          slot: "show_details1",
          width: 90,
          className: "centerText",
        },
        {
          title: "景数(成功/失败)",
          key: "show_imageNumber",
          slot: "show_imageNumber",
          width: 140,
          className: "centerText",
        },
        {
          title: "状态",
          key: "show_details2",
          slot: "show_details2",
          width: 90,
          className: "centerText",
        },
        {
          title: "操作",
          key: "show_details",
          slot: "show_details",
          className: "centerText",
          width: 160,
        },
      ],
      getAxios: {
        url: this.$api.taskManageApi.query, //请求路径
        method: "get", //请求方式
        dataList: {
          status: "1",
          userName: window.sessionStorage.getItem("user"),
        }, //请求参数
      },
      setIntervalTime: "",
    };
  },
  computed: {
    getColumn() {
      return [
        {
          key: "groupName",
          title: "任务名称",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "div",
                {
                  style: {
                    display: "inline-block",
                    width: "100%",
                    overflow: "hidden",
                    textOverflow: "ellipsis",
                    whiteSpace: "nowrap",
                  },
                  domProps: {
                    title: params.row.groupName,
                  },
                  props: {
                    color: "info",
                    variant: "outline",
                  },
                },
                params.row.groupName
              ),
            ]);
          },
        },
        {
          key: "createTime",
          title: "创建时间",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "div",
                {
                  style: {
                    display: "inline-block",
                    width: "100%",
                    overflow: "hidden",
                    textOverflow: "ellipsis",
                    whiteSpace: "nowrap",
                  },
                  domProps: {
                    title: params.row.createTime,
                  },
                  props: {
                    color: "info",
                    variant: "outline",
                  },
                },
                params.row.createTime
              ),
            ]);
          },
        },
        {
          key: "ms",
          title: "用时",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "div",
                {
                  style: {
                    display: "inline-block",
                    width: "100%",
                    overflow: "hidden",
                    textOverflow: "ellipsis",
                    whiteSpace: "nowrap",
                  },
                  domProps: {
                    title: params.row.ms,
                  },
                  props: {
                    color: "info",
                    variant: "outline",
                  },
                },
                params.row.ms
              ),
            ]);
          },
        },
        { key: "progress", title: "进度", align: "center" },
        { key: "successRate", title: "成功率", align: "center" },
        {
          key: "priorityLevel",
          title: "优先级",
          align: "center",
          render: (h, params) => {
            if (params.row.priorityLevel == 1) {
              return h("span", "优先");
            } else if (params.row.priorityLevel == 0) {
              return h("span", "普通");
            }
          },
        },
        {
          key: "status",
          title: "状态",
          align: "center",
          render: (h, params) => {
            if (params.row.status == 1) {
              return h("span", "执行中");
            } else if (params.row.status == 2) {
              return h("span", "暂停");
            } else if (params.row.status == 3) {
              return h("span", "删除");
            } else if (params.row.status == 4) {
              return h("span", "成功");
            } else if (params.row.status == 5) {
              return h("span", "失败");
            } else if (params.row.status == 6) {
              return h("span", "超时");
            } else if (params.row.status == 7) {
              return h("span", "停止");
            } else if (params.row.status == 8) {
              return h("span", "待执行");
            }
          },
        },
        {
          title: "操作",
          width: "240px",
          slot: "action",
          align: "center",
        },
      ];
    },
  },
  mounted() {
    // 查询子任务页面返回调用
    // if (this.$route.query.from === "taskChildren") {
      // this.currentPage = parseInt(this.$route.query.pageNum);
    // }
    /*   this.getTaskTableData();*/
    this.userName = window.sessionStorage.getItem("user");
    this.onStartTimeChange(this.startTime);
    this.onEndTimeChange(this.endTime);
  },
  methods: {
    qcReportModalClosed() {
      this.qcReportModal = false;
    },
    getTaskDetails(item) {
      if (item.taskType == 2) {
        this.$router.push({
          path: "/processing",
          query: {
            from: "taskLook",
            id: item.id,
            status: item.status,
          },
        });
      } else {
        this.qcReportModal = true;
        this.$refs.refQcReportModal.getTaskDetails(item, "parent");
      }
    },
    getVendorId(event) {
      let tempdata = event.target.value; //获取option对应的value值
      this.pageSize = parseInt(tempdata);
    },

    clearmess() {
      this.currentPage = 1;
      this.groupName = "";
      this.startDate = "";
      this.endDate = "";
      this.priority = "";
    // this.taskStatus = "";
      this.getTaskTableData();
    },
    // 输入框判断 start
    onStartTimeChange(startTime, type) {
      this.endTimeOption = {
        disabledDate(endTime) {
          // return endTime < new Date(startTime) || endTime > Date.now();
          return (
            endTime < new Date(startTime) - 8 * 60 * 60 * 1000 ||
            endTime > Date.now()
          );
        },
      };
    },
    onEndTimeChange(endTime, type) {
      this.startTimeOption = {
        disabledDate(startTime) {
          return startTime >= new Date(endTime) || startTime >= Date.now();
        },
      };
    },
    // end

    getInfo(val) {
      String.prototype.replaceAll = function (s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
      };
      let userLink =
        `/taskManage/allTask/${val.id}/${val.groupTaskName.replaceAll(
          "/",
          "*"
        )}` +
        "?"
        // +
        // val.number;
      this.$router.push({
        path: userLink,
        query: {
          // pageNum: this.currentPage,
          from: "taskExecute",
          taskType: val.taskType,
        },
      });
    },
    delCancel() {
      this.delShow = false;
    },
    del(val) {
      this.delShow = true;
      this.clickId = val.id;
    },
    delOk() {
      let self = this;
      this.delShow = false;
      let path = this.$api.taskManageApi.delete + this.clickId;
      this.http.delete(path).then((res) => {
        if (res.data.code == 0) {
          this.$Message.success("删除成功");
          self.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error("删除失败");
        }
      });
    },
    pause(val) {
      this.pauseShow = true;
      this.clickId = val.id;
    },
    pauseCancel() {
      this.pauseShow = false;
    },
    pauseOk() {
      let self = this;
      self.pauseShow = false;
      let statusName = "PAUSED";
      let path = this.$api.taskManageApi.updateStatus + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    restore(val) {
      this.restoreShow = true;
      this.clickId = val.id;
    },
    restoreCancel() {
      this.restoreShow = false;
    },
    restoreOk() {
      let self = this;
      this.restoreShow = false;
      let statusName = "RESUME";
      let path = this.$api.taskManageApi.updateStatus + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    reStart(val) {
      this.reStartShow = true;
      this.clickId = val.id;
    },
    reStartCancel() {
      this.reStartShow = false;
    },
    reStartOk() {
      let self = this;
      this.reStartShow = false;
      let statusName = "RESTART";
      let path = this.$api.taskManageApi.updateStatus +"/"+ this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    retry(val) {
      this.retryShow = true;
      this.clickId = val.id;
    },
    retryCancel() {
      this.retryShow = false;
    },
    retryOk() {
      let self = this;
      this.retryShow = false;
      let statusName = "RETRY";

      let path = this.$api.taskManageApi.updateStatus +"/"+ this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    stop(val) {
      this.stopShow = true;
      this.clickId = val.id;
    },
    stopCancel() {
      this.stopShow = false;
    },

    stopOk() {
      let self = this;
      this.stopShow = false;
      let path = this.$api.taskManageApi.updateStatus +"/"+ this.clickId;
      var formdata=new FormData();
      formdata.append("statusName","STOP");
      this.http.put(path, formdata).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    getTaskTableData(data=false) {
      let self = this;
      self.data = [];
      if (self.endDate == "Invalid date") {
        self.endDate = "";
      }
      if (self.startDate == "Invalid date") {
        self.startDate = "";
      }
      let path = this.$api.taskManageApi.query;
      let param = {
        currentPageNum:data,
        status: self.taskStatus,
        priority: self.priority,
        startTime: self.startDate,
        endTime: self.endDate,
        name: self.groupName,
        userName: this.userName,
      };
      this.$refs.table.getRefreshTable(param);
      /*  this.http.get(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          self.allNum = res.data.data.total;
          // self.data = res.data.data.dataList;

          let resData = res.data.data.dataList;
          let dataa = [];
          for (let i = 0; i < resData.length; i++) {
            // 截取掉时间
            let index = resData[i].groupTaskName.lastIndexOf(" ");
            let groupTaskNameNew2 = resData[i].groupTaskName.substring(
              0,
              index
            );
            dataa.push({
              createTime: resData[i].createTime,
              endTime: resData[i].endTime,
              failNumber: resData[i].failNumber,
              groupTaskName: resData[i].groupTaskName,
              taskSourceName: resData[i].taskSourceName,
              // groupTaskName:groupTaskNameNew2,
              id: resData[i].id,
              imageNumber: resData[i].imageNumber,
              number: resData[i].number,
              priority: resData[i].priority,
              runTime: resData[i].runTime,
              starTime: resData[i].startTime,
              status: resData[i].status,
              successNumber: resData[i].successNumber,
              taskType: resData[i].taskType,
              userId: resData[i].userId,
              workFlowId: resData[i].workFlowId,
            });
          }
          self.data = dataa;

          self.total = Math.ceil(res.data.data.total / self.pageSize);
          for (let i = 0; i < self.data.length; i++) {
            self.data[i].number =
              (self.currentPage - 1) * this.pageSize + i + 1;
            if (self.data[i].endTime == null) {
              self.data[i].endTime = "";
            }
          }
          // self.startDate = "";
          // self.endDate = "";
          // self.groupName = "";
        } else {
          this.$Message.error("查询失败");
        }
      });*/
    },
    selectPriorityChange(event, item) {
      let _this = this;
      let priority = event.target.value;
      let startWorkflowId = item.id;

      let url =
              _this.$api.taskManageApi.updateTaskPriority +
              priority +
              "/" +
              startWorkflowId;
      this.http
              .put(url)
              .then((res) => {
                if (res.data.code == 0) {
                  this.$Message.success("修改成功");
                  // 修改成功后 刷新右侧table
                  // _this.getTaskTableData(this.groupId);
                } else {
                  this.$Message.error(res.data.message);
                }
                // 修改后,不论成功与否，都刷新右侧table

                _this.getTaskTableData(this.groupId);
              })
              .catch((err) => {
                this.$Message.error("修改失败");
              });
    },
  },
  activated() {
    let that = this;
    that.getTaskTableData(true);
    that.$bus.$emit("getTaskCatalog");
    this.setIntervalTime = setInterval(
            function () {
              that.$bus.$emit("getTaskCatalog");
              that.getTaskTableData(true)
            }, 5000);
  },
  deactivated() {
    clearInterval( this.setIntervalTime)
  },



  watch: {
    data(newVal, oldVal) {
      this.$nextTick(function () {
        this.GlobalPermissionRender.render();
      });
    },
    groupName(newVal, oldVal) {
      if (newVal.length >= 50) {
        this.$Message.warning("任务名称长度不得超过50个字符");
      } else {
      }
      if (newVal != "") {
        this.changestatus = true;
      } else {
        this.changestatus = false;
      }
    },
    // pageSize(newVal, oldVal) {
    //   this.pageSize = newVal;
    //   this.getTaskTableData();
    // },
    // currentPage(newVal, oldVal) {
    //   this.currentPage = newVal;
    //   this.getTaskTableData();
    // },
    startDate(newVal, oldVal) {
      this.startDate = this.$moment(newVal).format("YYYY-MM-DD HH:mm:ss");
    },
    endDate(newVal, oldVal) {
      this.endDate = this.$moment(newVal).format("YYYY-MM-DD HH:mm:ss");
    },
  },
};
</script>

<!--css样式-->
<style scoped>
.myCol {
  margin-left: 10px;
}
.search {
  display: flex;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.76563rem;
  line-height: 1.5;
  border-radius: 0.2rem;
  width: 50px;
}
.table-responsive {
  height: 50% !important;
}
.labelName {
  margin-left: -15px;
  margin-right: 10px;
}
.headerFont {
  font-size: 18px;
}

.groupNameWidth {
  width: 197px;
}

.ivu-radio-wrapper {
  margin-left: 0px;
}

.dateMargin {
  margin-top: -5px;
}
.endMargin {
  margin-left: 20px;
}
.youxianji {
  margin-left: -5px;
  margin-right: 25px;
}
.ivu-radio-group {
  margin-top: 7px;
}
.btn-info {
  width: 90px;
}

.clean {
  margin-left: 10px;
}
.page-link {
  cursor: pointer;
}
.pageContent {
  margin-right: 26px;
  font-size: 14px;
}
.selectStyle {
  display: inline-block;
  width: 100px;
  margin-right: 5px;
}
.footerPage {
  display: flex;
  justify-content: flex-end;
  cursor: pointer;
  color: black;
}

/* xg */
.btnStyle {
  padding: 0;
  margin: 0 3px;
}
/* 用以调整表格位置 */
.tablePosition {
  margin-top: -23px;
  height: calc(100% - 130px);
  overflow-y: auto;
}

/* 搜索按钮位置 */
.searchPosition {
  margin-top: -10px;
}
/*
修改表格样式
*/
.oneMargin {
  margin: 10px;
}
.twoMargin {
}

.rowMargin {
}

/deep/ .row {
  margin-right: 0;
}

.card-body {
  overflow-y: auto;
  height: calc(100% - 52px) !important;
}

/deep/ .footerPage {
  padding-right: 0;
}

/deep/.ivu-table td.centerText {
  text-align: center;
  text-align: -moz-center;
  text-align: -webkit-center;
}
</style>
<style scoped>
.onButton:hover {
  color: white;
}
.tempxyz .card-body {
  position: static;
  padding: 0 20px;
}

.buttonStatus /deep/ .btn:focus {
  -webkit-box-shadow: 0 0 0 0;
  box-shadow: 0 0 0 0;
}


/deep/.ivu-table-cell {
  /* padding-left: 4px;
   padding-right: 4px;*/
  padding: 0;
  margin: 0;
}
/deep/.col-sm-9 {
  margin: 0;
  padding: 0;
}
.prioritySelect {
  width: 100%;
  margin: 0;
  padding: 0;
}
/deep/.form-control{
  padding: 0;
}
</style>
